import React from 'react';
import Listcontext from './Listcontext';
class Grandson extends React.Component {
    static contextType = Listcontext
    constructor(props) {
        super(props);
        this.toParent = this.toParent.bind(this)
    }
    toParent() {
        //React 提供的上下文的函数方法
        this.context.toParent('我是Grandson组件向父组件传的数据')
    }
    render() {
        return (
            <div style={{ backgroundColor: '#13ce66', padding: '10px', width: '200px', margin: 'auto', marginTop: '20px' }}>
                <p>通过Listcontext传过来：</p>
                <span style={{ color: 'blue' }}>{this.context.text}</span>
                <div onClick={this.toParent}>Listcontext向上传值</div>
            </div>
        )
    }
}

export default Grandson